package com.ykdl.app.connect;

import com.ykdl.app.bean.NetWorkStateBean;

import de.greenrobot.event.EventBus;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class NetworkReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		
		ConnectivityManager manager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
	     NetworkInfo gprs = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
	     NetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
	     if(gprs.isConnected() || wifi.isConnected())
	     {
	    	 EventBus.getDefault().post(new NetWorkStateBean(true));
	     }else {
	    	 EventBus.getDefault().post(new NetWorkStateBean(false));
	     }

	}

}
